package com.csp.session.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 多个资源管理
 *
 * @author:chengsp
 * @createTime:2019/8/22 17:43
 */
public class ResourceWrap {
    private List<PreparedStatement> preparedStatements;
    private List<ResultSet> resultSets;

    public ResourceWrap() {
        preparedStatements = new ArrayList<>();
        resultSets = new ArrayList<>();
    }

    public void addStatement(PreparedStatement preparedStatement) {
        preparedStatements.add(preparedStatement);
    }

    public void addResultSet(ResultSet resultSet) {
        resultSets.add(resultSet);
    }

    public void closeAll() {
        for (ResultSet resultSet : resultSets) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        for (PreparedStatement preparedStatement : preparedStatements) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
